﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Main.aspx.cs" Inherits="jnagr.Web.Main" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Expires" content="0" />
    <meta http-equiv="Cache-Control" content="no-cache" />
    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>现代农业生产管理服务平台</title>
    <script src="Script/easyui/jquery.min.js"></script>
    <script src="Script/easyui/jquery.easyui.min.js"></script>
    <script src="Script/easyui/locale/easyui-lang-zh_CN.js"></script>
    <script src="Script/changeEasyUITheme.js"></script>
    <link id="easyuiTheme" href="/Script/easyui/themes/default/easyui.css" rel="stylesheet" />
    <link href="Script/easyui/themes/icon.css" rel="stylesheet" />
    <%--<script src="Script/menu.js"></script>--%>
    <script src="Script/main.js"></script>
    <link href="CSS/default.css" rel="stylesheet" />
    <link href="CSS/list.css" rel="stylesheet" />
    <link href="CSS/IconExtension.css" rel="stylesheet" />
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.5&ak=6a5e0746feee514e8bb7b3f468a626d1">
    </script>
    <script type="text/javascript" src="http://api.map.baidu.com/library/TextIconOverlay/1.2/src/TextIconOverlay_min.js"></script>
	<script type="text/javascript" src="http://api.map.baidu.com/library/MarkerClusterer/1.2/src/MarkerClusterer_min.js"></script>
    <script type="text/javascript">  
        var _menus = '';        
        var theme;
        var myzu = "";
        var pturl = "http://www.xcforest.com";  
        //地图操作
        var sprovince = "";
        var scity = "";
        var scounty = "";
        var level;
        var markerClusterer;
        var markers = [];
        var pt;
        var uid = "";
        var map;
        var data_info;
        var opts;
        var icon1 = new BMap.Icon('../images/map1.gif', new BMap.Size(18, 34), { anchor: new BMap.Size(9, 34) });
        var icon2 = new BMap.Icon('../images/map2.gif', new BMap.Size(18, 34), { anchor: new BMap.Size(9, 34) });
        var icon3 = new BMap.Icon('../images/map3.gif', new BMap.Size(18, 34), { anchor: new BMap.Size(9, 34) });
        var icon4 = new BMap.Icon('../images/map4.gif', new BMap.Size(18, 34), { anchor: new BMap.Size(9, 34) });

        function InitMap() {
            map = new BMap.Map("mymap",{mapType:BMAP_SATELLITE_MAP});          // 创建地图实例 
            map.addControl(new BMap.MapTypeControl());   //添加地图类型控件
            map.enableScrollWheelZoom();
            var top_left_control = new BMap.ScaleControl({ anchor: BMAP_ANCHOR_TOP_LEFT });// 左上角，添加比例尺
            var top_left_navigation = new BMap.NavigationControl();  //左上角，添加默认缩放平移控件
            map.addControl(top_left_control);
            map.addControl(top_left_navigation);

        }
        
        
        function addClickHandler(content, marker) {
            marker.addEventListener("click", function (e) {
                openInfo(content, e);
                
            }
            );
        }
        function openInfo(content, e) {
            var p = e.target;
            var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);           
            var infoWindow = new BMap.InfoWindow(content);
            map.openInfoWindow(infoWindow, point); //开启信息窗口           
        }
        //初始化表格
        function InitGird() {
            $('#tt').datagrid({
                //title: '测报点列表', //表格标题
                url: 'mapinfo/GetMaps.ashx', //请求数据的页面
                sortName: 'mname', //排序字段
                idField: 'mid', //标识字段,主键
                iconCls: '', //标题左边的图标
                width: '95%', //宽度
                height: '95%', //高度
                nowrap: false, //是否换行，True 就会把数据显示在一行里
                striped: true, //True 奇偶行使用不同背景色
                collapsible: false, //可折叠
                sortOrder: 'desc', //排序类型
                remoteSort: true, //定义是否从服务器给数据排序
                fitColumns: true,
                singleSelect: true,
                method: 'post',
                columns: [[                    
	                { title: '测报站名', field: 'mname', width: 80, sortable: true }                    
                ]],
                toolbar: "#tab_toolbar",
                queryParams: { "action": "queryc" },               
                pageNumber: 1, //默认索引页
                pageSize: 200, //默认一页数据条数
                rownumbers: true, //行号
                pageList: [10, 20, 50, 200, 500],
                pagination: true, //是否开启分页
                onLoadSuccess: function (data) {
                    data_info = [];
                    map.clearOverlays();
                    $.each(data.rows, function (k, v) {
                        data_info.push({ "lng": v["mjd"], "lat": v["mwd"], "mlevel": v["mlevel"], "mname": v["mname"], "uname": v["uname"], "madd": v["madd"], "mpic": v["mpic"], "uid": v["uid"], "remark": v["remark"] });
                    });
                    var mlevel;
                    var marker;
                   
                    pt = "";
                    if (markers.length > 0)
                    {
                        if(markerClusterer!=null)
                            markerClusterer.removeMarkers(markers);
                        markers = [];
                    }
                    
                    for (var i = 0; i < data_info.length; i++) {
                        mlevel = data_info[i].mlevel;
                        pt = new BMap.Point(data_info[i].lng, data_info[i].lat);
                        if (mlevel == '4')
                            marker = new BMap.Marker(pt, { icon: icon4 });                            
                        else if (mlevel == '3')
                            marker =new BMap.Marker(pt, { icon: icon3 });
                        else if (mlevel == '2')
                            marker =new BMap.Marker(pt, { icon: icon2 });
                        else if (mlevel == '1')
                            marker =new BMap.Marker(pt, { icon: icon1 });
                        var content = "<h4 style='margin:0 0 5px 0;padding:0.2em 0'>" + data_info[i].mname + "</h4><img style='float:right;margin:4px' id='imgDemo' src='" + data_info[i].mpic + "' width='139' height='104' />" + data_info[i].madd + "<br\><a onclick=\"top.addTab(\'设备数据" + data_info[i].uname + "\',\'/mapinfo/listusername.aspx?uname=" + data_info[i].uname + "\', \'icon icon-magic\');\" href='#'>设备数据</a><br/><a onclick=\"top.addTab(\'虫情" + data_info[i].uname + "\',\'/ForestPets/listr.aspx?uid=" + data_info[i].uid + "&qh=" + data_info[i].remark + "\', \'icon icon-magic\');\" href='#'>虫情数据</a>";
                        map.addOverlay(marker);
                        markers.push(marker);
                        addClickHandler(content, marker);
                    }
                    //增加级别
                    if(level<4)
                    {
                        if (scounty != "")
                            map.centerAndZoom(scounty, 12);
                        else if (scity != "")
                            map.centerAndZoom(scity,10);
                        else if (sprovince != "")
                            map.centerAndZoom(sprovince,8);
                    }
                    else
                        map.centerAndZoom("西安", 5);
                    //运行时JS有问题
                    var markerClusterer = new BMapLib.MarkerClusterer(map, { markers: markers });//对地图扩大缩小后会都所有的点全显示出来。
                    
                }
            });
            $('#tt').datagrid('getPager').pagination({
                layout: ['list', 'prev', 'next', 'refresh']
            });
        }



        Date.prototype.pattern = function (fmt) {
            var o = {
                "M+": this.getMonth() + 1, //月份        
                "d+": this.getDate(), //日        
                "h+": this.getHours() % 12 == 0 ? 12 : this.getHours() % 12, //小时        
                "H+": this.getHours(), //小时        
                "m+": this.getMinutes(), //分        
                "s+": this.getSeconds(), //秒        
                "q+": Math.floor((this.getMonth() + 3) / 3), //季度        
                "S": this.getMilliseconds() //毫秒        
            };
            var week = {
                "0": "/u65e5",
                "1": "/u4e00",
                "2": "/u4e8c",
                "3": "/u4e09",
                "4": "/u56db",
                "5": "/u4e94",
                "6": "/u516d"
            };
            if (/(y+)/.test(fmt)) {
                fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
            }
            if (/(E+)/.test(fmt)) {
                fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? "/u661f/u671f" : "/u5468") : "") + week[this.getDay() + ""]);
            }
            for (var k in o) {
                if (new RegExp("(" + k + ")").test(fmt)) {
                    fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
                }
            }
            return fmt;
        }
        var Common = {

            //EasyUI用DataGrid用日期格式化
            TimeFormatter: function (value, rec, index) {
                if (value == undefined) {
                    return "";
                }
                /*json格式时间转js时间格式*/
                value = value.substr(1, value.length - 2);
                var obj = eval('(' + "{Date: new " + value + "}" + ')');
                var dateValue = obj["Date"];
                if (dateValue.getFullYear() < 1900) {
                    return "";
                }
                var val = dateValue.pattern("yyyy-MM-dd HH:mm");
                return val;
            },
            DateTimeFormatter: function (value, rec, index) {

                if (value == null || value == '') {
                    return '';
                }
                var dt;
                if (value instanceof Date) {
                    dt = value;
                }
                else {
                    dt = new Date(value);
                    if (isNaN(dt)) {
                        value = value.replace(/\/Date\((-?\d+)\)\//, '$1'); //标红的这段是关键代码，将那个长字符串的日期值转换成正常的JS日期格式
                        dt = new Date();
                        dt.setTime(value);
                    }
                }
                return dt.pattern("yyyy年M月d日");
            },

            //EasyUI用DataGrid用日期格式化
            DateFormatter: function (value, rec, index) {
                if (value == undefined) {
                    return "";
                }
                /*json格式时间转js时间格式*/
                value = value.substr(1, value.length - 2);
                var obj = eval('(' + "{Date: new " + value + "}" + ')');
                var dateValue = obj["Date"];
                if (dateValue.getFullYear() < 1900) {
                    return "";
                }

                return dateValue.pattern("yyyy-MM-dd");
            }
        };       
        function showData(value) {
            //清空内容            
            //$('#dlg').dialog('open').dialog('setTitle', '信息');
            var row = $('#tt').datagrid('getSelected');
            if (row == null) {
                $.messager.alert("提示", "请选择要显示的行！", "info");
            }
            if (row) {
                $('#dlgmsg').dialog('open').dialog('setTitle', '详细信息');
                $("#caname").text(row.caname);
                $("#stitle").text(row.title);
                $("#suname").text(row.uname);
                var result = $.ajax({
                    url: "../info/GetInfo.ashx?action=getinfo&iid=" + row.iid,
                    type: 'post',
                    dataType: 'json',
                    async: false,
                    cache: false
                }).responseText;
                //$("#psinfo").html(result);
                $('#infocontent').html(result);
            }
        }
        function getLevelname(level) {
            var lname="";
            if (level == "0")
                lname = "普通用户";
            else if (level == "1")
                lname = "县级用户";
            else if (level == "2")
                lname = "市级用户";
            else if (level == "3")
                lname = "省级用户";
            else if (level == "4")
                lname = "全国用户";
            else if (level == "5")
                lname = "管理员";
            else if (level == "-1")
                lname = "省级代理商";
            return lname;

        }
        $(function () {
            $("#editpass").click(function () {
                $('#w').window('open');
            });
            $('#btnEp').click(function () {
                serverLogin();
            });

            $('#btnCancel').click(function () {
                closePwd();
            })
            $.ajax({
                url: "ashx/SysMenu.ashx?Method=GetMenuByUserID",
                dataType: 'text',
                type: "post",
                success: function (returnData) {
                    _menus = eval('(' + returnData + ')');
                    InitLeftMenu();
                }
            });
            $.ajax({
                type: "post",
                dataType: "json",
                url: "admin/getinfo.ashx?action=level",
                success: function aa(data) {
                    level = data[0].level;
                    var name = data[0].name;
                    var uadd = data[0].province + data[0].city + data[0].county + data[0].uadd;
                    $("#myinfos").text("用户名：" + name + " 地址：" + uadd + " 用户权限:" + getLevelname(level));
                    //地图加载
                    sprovince = data[0].province;
                    scity = data[0].city;
                    scounty = data[0].county;
                    //InitMap();
                    //InitGird();
                   
                }
            });            
            
            tabClose();
            tabCloseEven();
            openPwd();
            $("#info").window("close");            
            if ($.cookie('easyuiThemeName')) {
                changeThemeFun($.cookie('easyuiThemeName'));
                theme = $.cookie('easyuiThemeName');
            }            
            $('#loginOut').click(function () {
                $.messager.confirm('系统提示', '您确定要退出本次登录吗?', function (r) {
                    if (r) {
                        location.href = 'loginout.aspx';
                    }
                });
            });
            $('#myinfo').click(function () {
                $.ajax({
                    type: "post",
                    dataType: "json",
                    url: "userinfo/GetUser.ashx?action=myinfo",
                    success: function aa(data) {
                        $("#uname").text(data.rows[0].uname);
                        $("#uprovince").text(data.rows[0].uprovince + data.rows[0].ucity + data.rows[0].ucounty);
                        $("#uunit").text(data.rows[0].uunit);
                        $("#utruename").val(data.rows[0].utruename);
                        $("#uphone").val(data.rows[0].uphone);
                        $("#uemail").val(data.rows[0].uemail);
                        $("#utel").val(data.rows[0].utel);
                        $("#uadd").val(data.rows[0].uadd);
                    }
                });
                $('#dlg').dialog('open').dialog('setTitle', '个人信息');
            }); 
        });
        function saveUser() {            
            $('#fm').form('submit', {
                url: "userinfo/GetUser.ashx?action=updatemyinfo",
                onSubmit: function () {
                    return $(this).form('validate');
                },
                success: function (result) {
                    if (result.indexOf("T") == 0) {
                        $('#dlg').dialog('close');                            
                        $.messager.alert("提示", "恭喜您，信息修改成功", "info");
                    }
                    else if ((result.indexOf("F") == 0)) {
                        $.messager.alert("提示", "修改失败，请重新操作！", "info");
                        return;
                    }
                    else if ((result.indexOf("L") == 0)) {
                        $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                        top.location = '/index.aspx';
                        return;
                    }
                }
            });           
        }
       
    </script>
    <style type="text/css">
        * {
            margin: 0px;
            padding: 0px;
            border: 0px;
        }

        #myul {
            width: 90%;
            height: 600px;
        }

            #myul li {
                list-style-type: none;
                float: left;
                width: 210px;
                text-align: center;
                margin: 5px;
            }

            #myul span {
                color: orange;
                font-size: 24px;
            }

            #myul img {
                border: 0px;
            }
    </style>
</head>
<body class="easyui-layout" style="overflow-y: hidden" scroll="no">
    <noscript>
        <div style="position: absolute; z-index: 100000; height: 2046px; top: 0px; left: 0px; width: 100%; background: white; text-align: center;">
            <img src="images/noscript.gif" alt='抱歉，请开启脚本支持！' />
        </div>
    </noscript>
    <div region="north" border="false" style="overflow: hidden; height: 73px; background: url(images/top1.jpg);">
        <div style="overflow: hidden; height: 73px; background: url(images/top.jpg) no-repeat; width:391px;float:left;">
        </div>
        <div style="float: right; text-align: right; padding-right: 20px; margin-top: 15px;line-height: 20px; color: #fff; font-family: Verdana, 微软雅黑,黑体" class="head">
            <a href="#" id="mb" class="easyui-menubutton" data-options="menu:'#menu',iconCls:'icon-ok'">换肤</a>           
            <a href="#" id="myinfo">个人信息</a> <a href="#" id="editpass">修改密码</a>
            <a href="#" id="loginOut">安全退出</a><br />
            欢迎 <span id="myinfos"></span></div>
    </div>
    <div region="south" style="height: 30px; ">
        <div class="footer">智慧农业</div>
    </div>
    <div region="west" split="true" title="导航菜单" style="width: 180px;" id="west">
        <div class="easyui-accordion1" fit="true" border="false">
            <!--  导航内容 -->



        </div>

    </div>
    <div id="mainPanle" region="center" style="background: #eee; overflow-y: hidden">
        <div id="tabs" class="easyui-tabs" fit="true">
            <div title="欢迎使用" style="padding: 5px; overflow: hidden;" id="home">
                <div style="display:none;">
                <table id="tt" ></table>
                    </div>
                <div style="background: #eee; overflow: auto;height:100%;width:100%;">  
                 <div id="mymap"  style="height:100%;width:100%;"></div>   
                    </div>
                <%--<ul id="myul">
                    <li>
                        <a href="#" onclick="addTab('虫害','/ForestPets/list.aspx', 'icon icon-bug')">
                            <img alt="" src="Images/mpics/ch.jpg" />
                            <span>虫害</span>
                        </a>
                    </li>
                    <li>
                        <a href="#" onclick="addTab('病害','/ForestSickness/list.aspx', 'icon icon-pill')">
                            <img alt="" src="Images/mpics/bh.jpg" />
                            <span>病害</span>
                        </a>
                    </li>
                    <li>
                        <a href="#" onclick="addTab('草害','/ForsetGrass/list.aspx', 'icon icon-build')">
                            <img alt="" src="Images/mpics/cch.jpg" />
                            <span>草害</span>
                        </a>
                    </li>
                    <li>
                        <a href="#" onclick="addTab('鼠害','/ForestRat/list.aspx', 'icon icon-vector')">
                            <img alt="" src="Images/mpics/sh.jpg" />
                            <span>鼠害</span>
                        </a>
                    </li>
                    <li>
                        <a href="#" onclick="addTab('测报点查看','/mapinfo/listmy.aspx', 'icon icon-building_go')">
                            <img alt="" src="Images/mpics/cbd.jpg" />
                            <span>测报点查看</span>
                        </a>
                    </li>
                    <li>
                        <a href="#" onclick="addTab('气候数据','/weatherinfo/List.aspx', 'icon icon-weather_cloudy_rain')">
                            <img alt="" src="Images/mpics/rain.png" />
                            <span>气候数据</span>
                        </a>
                    </li>
                </ul>--%>

            </div>
        </div>
    </div>
    <div id="w" class="easyui-window" title="修改密码" collapsible="false" minimizable="false"
        maximizable="false" icon="icon-save" style="width: 300px; height: 150px; padding: 5px; background: #fafafa;">
        <div class="easyui-layout" fit="true">
            <div region="center" border="false" style="padding: 10px; background: #fff; border: 1px solid #ccc;">
                <table cellpadding="3">
                    <tr>
                        <td>旧密码：
                        </td>
                        <td>
                            <input id="OldPassword" name="OldPassword" type="Password" class="easyui-validatebox" required="true" />
                        </td>
                    </tr>

                    <tr>
                        <td>新密码：</td>
                        <td>
                            <input id="NewPassword" type="Password" class="txt01" /></td>
                    </tr>
                    <tr>
                        <td>确认密码：</td>
                        <td>
                            <input id="txtRePass" type="Password" class="txt01" /></td>
                    </tr>
                </table>
            </div>
            <div region="south" border="false" style="text-align: right; height: 40px; line-height: 30px;">
                <a id="btnEp" class="easyui-linkbutton" icon="icon-ok" href="javascript:void(0)">确定</a> <a id="btnCancel" class="easyui-linkbutton" icon="icon-cancel" href="javascript:void(0)">取消</a>
            </div>
        </div>
    </div>
    <div id="menu" class="easyui-menu" style="width: 120px;">
        <div onclick="changeThemeFun('default')">Default</div>
        <div onclick="changeThemeFun('gray')">Gray</div>
        <div onclick="changeThemeFun('black')">Black</div>
        <div onclick="changeThemeFun('bootstrap')">bootstrap</div>
        <div onclick="changeThemeFun('metro')">metro</div>
        <div onclick="changeThemeFun('metro-blue')">metro-blue</div>
        <div onclick="changeThemeFun('metro-gray')">metro-gray</div>
        <div onclick="changeThemeFun('metro-green')">metro-green</div>
        <div onclick="changeThemeFun('metro-orange')">metro-orange</div>
        <div onclick="changeThemeFun('metro-red')">metro-red</div>
        <div onclick="changeThemeFun('ui-cupertino')">ui-cupertino</div>
        <div onclick="changeThemeFun('ui-dark-hive')">ui-dark-hive</div>
        <div onclick="changeThemeFun('ui-pepper-grinder')">ui-pepper-grinder</div>
        <div onclick="changeThemeFun('ui-sunny')">ui-sunny</div>

    </div>
    <div id="mm" class="easyui-menu" style="width: 150px;">
        <div id="mm-tabclose">关闭</div>
        <div id="mm-tabcloseall">全部关闭</div>
        <div id="mm-tabcloseother">除此之外全部关闭</div>
        <div class="menu-sep"></div>
        <div id="mm-tabcloseright">当前页右侧全部关闭</div>
        <div id="mm-tabcloseleft">当前页左侧全部关闭</div>
        <div class="menu-sep"></div>
        <div id="mm-exit">退出</div>
    </div>
    <div id="dlg" class="easyui-dialog" style="width: 400px; height: auto; padding: 10px 20px"
        data-options="closed:true,buttons:'#dlg-buttons',shadow:false">

        <form id="fm" method="post">

            <div class="fitem">
                <label>用户名：</label>
                <span id="uname"></span>
            </div>
            <div class="fitem" id="dprovince">
                <label>地区：</label>
                <span id="uprovince"></span>
            </div>
            <div class="fitem">
                <label>单位：</label>
                <span id="uunit"></span>
            </div>
            <div class="fitem">
                <label>负责人姓名：</label>
                <input id="utruename" name="utruename" class="easyui-validatebox" data-options="required:true" />
            </div>
            <div class="fitem">
                <label>手机：</label>
                <input id="uphone" name="uphone" class="easyui-validatebox" data-options="required:true" />
            </div>
            <div class="fitem">
                <label>邮箱：</label>
                <input id="uemail" name="uemail" class="easyui-validatebox" data-options="required:true,validType:'email'" />
            </div>

            <div class="fitem">
                <label>单位电话：</label>
                <input id="utel" name="utel" class="easyui-validatebox" data-options="required:true" />
            </div>

            <div class="fitem">
                <label>地址：</label>
                <input id="uadd" name="uadd" class="easyui-validatebox" />
            </div>
        </form>

    </div>
    <div id="dlg-buttons">
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="saveUser()">保存</a>
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="javascript:$('#dlg').dialog('close')">关闭</a>
    </div>
    <div id="dlgmsg" class="easyui-dialog" style="width: 850px; height: auto; padding: 10px 20px"
        data-options="closed:true,buttons:'#Div2',shadow:false,top:50">
        <form id="Form1" method="post">
            <div class="fitem">
                <label>群组名：</label>
                <span id="caname"></span>
            </div>
            <div class="fitem">
                <label>标题：</label>
                <span id="stitle"></span>
            </div>
            <div class="fitem">
                <label>作者：</label>
                <span id="suname"></span>
            </div>
            <div>
                <label>内容：</label>

                <span id="infocontent"></span>
                <input name="iid" id="iid" type="hidden" />
                <input id="key" name="key" onkeydown="if(event.keyCode==13)reloadgrid()" type="hidden" />
            </div>
            <div>
            </div>
        </form>
    </div>
    <div id="Div2">
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="javascript:$('#dlgmsg').dialog('close')">关闭</a>
    </div>
    <div id="notity"></div>
</body>
</html>
